#include "data_handle_memory_task.h"

u8 times = 0;
GatherTargetData HandledData;



/*
return value:
                1:有故障
                0:没有故障
*/
u8 CleanData (const GatherData *source){
    
    if (source->temp > 200)
    {
        times++;
        if (times>10)  //消除误差抖动，确实发生故障
        {
            HeartState = 0;
            times = 0;
            return 1;
        }
    }else
    {
        HeartState = 1;
        times = 0;
        return 0;
    }
    return 0;
}

void ProcessData (const GatherData *source, GatherTargetData * const result){

    result->humi = source->humi;
    result->raidrop = source->raidrop;
    result->temp = source->temp;
    result->smoke = source->smoke / 40;
    result->sunshine = 100 - source->sunshine / 40;

}



 void DataHandle(GatherData *source){
    if (source == NULL)
    {
        printf("source data err:source is NULL\r\n");
        return;
    }

    u8 ret = CleanData(source);
    if (ret)
    {
        printf("machine error\r\n");
        return ;
    }
        
    if (!HeartState)
    {
        return;
    }
    
    ProcessData(source,&HandledData);
 }



